import { Base } from "./base";

export class Wiki extends Base {
  /**
   *
   * @param name
   * @param cate_id
   * @param pageNum
   * @param pageSize
   * @returns {Promise<void>}
   */
  // eslint-disable-next-line camelcase
  async list({ cate_id, name, pageNum = 1, pageSize = 10 }) {
    const { data = {} } = await this.$http("post", "/api/wiki", {
      cate_id,
      name,
      pageNum,
      pageSize
    });
    return data;
  }

  /**
   *
   * @param id
   * @returns {Promise<boolean>}
   */
  async del(id) {
    const { errno } = await this.$http("post", "/api/wiki/del", { id });
    return errno === 0;
  }

  /**
   *
   * @param form
   * @returns {Promise<void>}
   */
  async add(form) {
    const { errno, data } = await this.$http("post", "/api/wiki/add", {
      ...form
    });
    return errno === 0 ? data : false;
  }

  /**
   *
   * @param id
   * @param form
   * @returns {Promise<void>}
   */
  // eslint-disable-next-line camelcase
  async update({ id, ...form }) {
    const { errno } = await this.$http("post", "/api/wiki/update", {
      id,
      ...form
    });
    return errno === 0;
  }

  /**
   *
   * @param id
   * @returns {Promise<void>}
   */
  async detail(id) {
    const { data } = await this.$http("post", "/api/wiki/detail", {
      id
    });
    return data;
  }
}
